package org.rcgwt.client.model;

public abstract class Reflected<B> {
    private final B bean;

    protected Reflected(B bean) {
        this.bean = bean;
    }

    /**
     * Get bean property
     * 
     * @param property
     *            Property name
     * @return Property value
     */
    public Object get(String property) {
        return callGetter(bean, property);
    }

    /**
     * Set bean property.
     * 
     * @param property
     *            Property name
     * @param value
     *            Property value
     */
    public void set(String property, Object value) {
        callSetter(bean, property, value);
    }

    /**
     * Invoke the getter on the bean. Will be implemented by the generator.
     * 
     * @param bean
     *            bean object.
     * @param property
     *            Property name
     * @return Property value
     * @throws ReflectionException
     */
    protected abstract Object callGetter(B bean, String property)
            throws ReflectionException;

    /**
     * Invoke the setter on the bean. Will be implemented by the generator.
     * 
     * @param bean
     *            bean object.
     * @param property
     *            Property name
     * @param value
     *            Property value
     * @throws ReflectionException
     */
    protected abstract void callSetter(B bean, String property, Object value)
            throws ReflectionException;

    public B getBean() {
        return bean;
    }
}
